package com.btl.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtils {

	public static String getDate(String date) {

		String[] strs = date.split(" ");
		String num = getTwoDay(getStringDateShort(), strs[0]);
		if(num.equals("1")) {
			return "昨天" + "  " + strs[1].substring(0,strs[1].lastIndexOf(":"));
		} else if(num.equals("0")) {
			return "今天" + "  " + strs[1].substring(0,strs[1].lastIndexOf(":"));
		} else{
			
			
			return getMonth(strs[0]);
		}
	}

	

	private static String getMonth(String date) {
		
		String[] strs2 = getStringDateShort().split("-");
		
		String[] strs = date.split("-");
		String str = "";
		
		if(!strs2[0].equals(strs[0])) {
			
			str = strs[0] + "年" ;
		}
		
		if(strs[1].charAt(0) == 0) {
			str = str + strs[1].charAt(1) + "月";
		} else {
			str = str + strs[1] + "月"; 
		}
		
		if(strs[2].charAt(0) == 0) {
			str = str + strs[2].charAt(1) + "日";
		} else {
			str = str + strs[2] + "日"; 
		}
		
		
		return str;
	}



	public static String getStringDateShort() {
		Date currentTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = formatter.format(currentTime);
		return dateString;
	}

	public static String getTwoDay(String sj1, String sj2) {
		SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
		long day = 0;
		try {
			Date date = myFormatter.parse(sj1);
			Date mydate = myFormatter.parse(sj2);
			day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
		} catch (Exception e) {
			return "";
		}
		return day + "";
	}

	

}
